package com.jsd2412.backend.consult.service.impl;

import com.jsd2412.backend.consult.mapper.ConsultMapper;
import com.jsd2412.backend.consult.pojo.dto.ConsultQuery;
import com.jsd2412.backend.consult.pojo.dto.ConsultSaveParam;
import com.jsd2412.backend.consult.pojo.entity.Consult;
import com.jsd2412.backend.consult.pojo.vo.ConsultVO;
import com.jsd2412.backend.consult.service.ConsultService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class ConsultServiceImpl implements ConsultService {
    @Autowired
    private ConsultMapper consultMapper;

    @Override
    public void saveConsult(ConsultSaveParam consultSaveParam) {
        log.debug("保存接待业务:参数={}", consultSaveParam);
        Consult consult = new Consult();
        BeanUtils.copyProperties(consultSaveParam, consult);
        if (consultSaveParam.getId() == null) {//新增
            consult.setCreateTime(new Date());
            consultMapper.insert(consult);
        } else {//更新
            consultMapper.update(consult);
        }
    }

    @Override
    public void deleteConsult(Long id) {
        log.debug("删除接待业务:参数={}", id);
        consultMapper.deleteById(id);
    }

    @Override
    public List<ConsultVO> selectConsult(ConsultQuery consultQuery) {
        log.debug("查询接待业务:参数={}", consultQuery);
        return consultMapper.selectConsult(consultQuery);
    }
}
